﻿app.factory('userFactory', function ($http) {
    var factory = {};

    factory.getUsers = function (data) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.post(getUsersApiAddress, data);
    };
    factory.getByGroup = function (data) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.post(getUsersByGroupApiAddress, data);
    };
    factory.getUser = function (id) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.get(getUserApiAddress + id);
    };
    factory.postUser = function (dataPost) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.post(createUserApiAddress, dataPost);
    };
    factory.putUser = function (dataPost) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.post(updateUserApiAddress, dataPost);
    };
    factory.login = function (authen) {
        var ob = { Authen: authen };
        $http.defaults.headers.common['Authorization'] = authen;
        return $http.post(getUserWithAuthenApiAddress, ob);
    };
    factory.blockOrActive = function (id) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.post(updateBlockApiAddress + id);
    };
    factory.delUser = function (id) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.post(delUserApiAddress + id);
    };
    factory.searchUser = function (dataPost) {
        $http.defaults.headers.common['Authorization'] = localStorage.getItem('authen');
        return $http.post(searchUserApiAddress, dataPost);
    };
    factory.checkEmail = function (dataPost) {
        return $http.post(checkEmailApiAddress, dataPost);
    };
    factory.checkUser = function (dataPost) {
        return $http.post(checkUserApiAddress, dataPost);
    };
    factory.changePassword = function (dataPost) {
        return $http.post(changePasswordApiAddress, dataPost);
    };
    factory.searchFriend = function (friendPost) {
        return $http.post(searchUserApiAddress, friendPost);
    };
    return factory;
});